FROM php:7.0.8-fpm

MAINTAINER wenlong11@staff.weibo.com

ENV PATH $PATH:/root/.composer/vendor/bin

#加速apt
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
   echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list && \
   echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list && \
   echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list && \
   echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list


   RUN apt-get update \
    && apt-get -y install \
            git \
            g++ \
            apt-utils \
            libicu-dev \
            zlib1g-dev \
            libfreetype6-dev \
            libjpeg-dev \
            libpng-dev \
            nginx \
        --no-install-recommends

RUN apt-get -y install \
    libevent-dev \
    libmemcached-dev zlib1g-dev \
    --no-install-recommends
#RUN  curl -O https://raw.githubusercontent.com/php/php-src/master/php.ini-development \
#    && mv php.ini-development /usr/local/etc/php/conf.d/php.ini

ADD php.ini /usr/local/etc/php/conf.d/php.ini  

RUN docker-php-ext-install intl \
    && docker-php-ext-install pdo_mysql \
    && docker-php-ext-install mbstring \
    && docker-php-ext-install opcache \
    && docker-php-ext-install zip \
    && docker-php-ext-install iconv \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install gd \
    && pecl install apcu-5.1.8 && echo extension=apcu.so > /usr/local/etc/php/conf.d/apcu.ini \
    && pecl install redis && echo extension=redis.so > /usr/local/etc/php/conf.d/redis.ini \
    && apt-get purge -y g++ \
    && apt-get autoremove -y \
    && rm -r /var/lib/apt/lists/* \
    && echo "\nclear_env = no" >> /usr/local/etc/php-fpm.conf \
    && usermod -u 1000 www-data

RUN curl -sS https://getcomposer.org/installer | php \
    && mv composer.phar /usr/local/bin/composer 

RUN pecl install yaf \
    && pecl install yac-2.0.2 \
    && echo extension=/usr/local/lib/php/extensions/no-debug-non-zts-20151012/yaf.so > /usr/local/etc/php/conf.d/yaf.ini \
    && echo extension=/usr/local/lib/php/extensions/no-debug-non-zts-20151012/yac.so > /usr/local/etc/php/conf.d/yac.ini

#RUN pecl install memcached \
#    && echo extension=/usr/local/lib/php/extensions/no-debug-non-zts-20151012/memcached.so > /usr/local/etc/php/conf.d/memcached.ini

RUN docker-php-ext-install sockets

RUN pecl install memcached \
    && echo extension=/usr/local/lib/php/extensions/no-debug-non-zts-20151012/memcached.so > /usr/local/etc/php/conf.d/memcached.ini


WORKDIR /var/www/html

RUN  mkdir /var/www/html/app \
    && mkdir -p /var/www/html/nginx/vhosts \
    && mkdir /var/www/html/logs \
    && mkdir /var/www/html/data \
    && mkdir /var/www/html/cache \
    && chown www-data:www-data -R /var/www/html 

ADD fpm.conf /usr/local/etc/php-fpm.d/fpm.conf
ADD nginx.conf /var/www/html/nginx/
ADD fastcgi_params /etc/nginx/fastcgi_params
ADD start.sh /var/www/html/nginx/start.sh
RUN chmod +x /var/www/html/nginx/start.sh

EXPOSE 80
EXPOSE 9000

CMD ["/var/www/html/nginx/start.sh"]
